<template>
	<!-- 上拉下拉列表组件示例 -->
	<view>
		<c-scroll-list ref="list" :api="getList" :apiParams="apiParams" :option="option" @load="(res)=>(list=res)">
			<view v-for="v in list.list" :key="v.id">
				<view>{{v.id}}</view>
				<view>{{v.name}}</view>
				<view>{{v.text}}</view>
			</view>
		</c-scroll-list>
	</view>
</template>

<script>
	import {
		getApi
	} from '../../../api/http.api'

	export default {
		data() {
			return {
				apiParams: { //这是接口参数

				},
				// option: { //这是配置信息
				// 	auto: false
				// },
				scrollList: [],
				list: []
			}
		},
		onShow() {
			this.$refs.list.initList(true)
		},
		created() {
			this.initData(10)
		},
		methods: {
			getApi,
			getList() {
				let that = this
				return new Promise((resolve, reject) => { //通过new方法创建Promise
					resolve({
						data: {
							list: [{
									id: 1,
									name: '这是1',
									text: '这是1的text'
								},
								{
									id: 2,
									name: '这是2',
									text: '这是2的text'
								},
								{
									id: 3,
									name: '这是3',
									text: '这是3的text'
								}
							],
							total: 3
						}
					}); //调用成功的回调函数
				})
			},
			// 定义数据 x=多少条数据
			initData(x) {
				for (let i = 1; i <= x; i++) {
					let obj = {
						id: i,
						label: '选项' + i,
						value: '这是选项' + i + '的值'
					}
					this.scrollList.push(obj)
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
</style>